from threading import Thread
from time import sleep


def fn(name):
    print(f"线程{name}启动")
    for i in range(3):
        print(f"线程{name} {i}")
        sleep(0.5)
    print(f"线程{name}结束")


if __name__ == "__main__":
    print("主线程启动")

    t1 = Thread(target=fn, args=("foo",))
    t2 = Thread(target=fn, args=("bar",))

    t1.start()
    t2.start()

    # -- join：等待子线程结束 --
    t1.join()
    t2.join()

    print("主线程结束")
